package walka;

import postacie.Postac;
import wyjatki.WyjatekWalka;

import java.util.Random;

public class WalkaAutomatyczna implements WalkaInterface {
    @Override
    public Postac walcz(Postac a, Postac b) throws WyjatekWalka {
        Random random = new Random(47);
        while (a.getLiczbaHP() > 0 || b.getLiczbaHP() > 0){
            boolean aOrB = random.nextBoolean();
            if (aOrB){
                if (!a.obrona(b.atak()))
                    return b;
            } else {
                if (b.obrona(a.atak()))
                    return a;
            }
        }

        if (a.getLiczbaHP() < 0)
            return b;
        else
            return a;
    }
}
